package com.zhang;

public class TestException {

    public static void main(String[] args) {
//        int a=10/0;
//        Exception in thread "main" java.lang.ArithmeticException: / by zero
//        at com.zhang.TestException.main(TestException.java:6)

//        try {
//            Object o = null;
//            o.equals("");
//            int b=10/0;
//        }catch (NullPointerException ex){
//            ex.printStackTrace();
//        }catch (ArithmeticException ex){
//            ex.printStackTrace();
//        }


        TestException testException = new TestException();
        try {
            int calculate = testException.calculate(0);
        } catch (ArithmeticException e) {
            e.printStackTrace();
        }

        try {
            testException.myDefined();
        }catch(MyException myException){
            System.out.println(myException.getMessage());
        }

    }

    public int calculate(int b) throws ArithmeticException{
        return 10/b;
    }

    public void myDefined() throws  MyException{
        throw new MyException("异常描述：money is little");
    }

    class MyException extends Exception{
        public MyException() {
        }

        public MyException(String message) {
            super(message);
        }
    }
}
